package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;

import tools.Tab;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TabView extends javax.swing.JFrame implements ActionListener {

	private static final long serialVersionUID = 1L;
	private JScrollPane tabScrollPane;
	private JButton saveButton;
	private JTextArea tabTextArea;
	private JPanel tabViewPanel;

	private Tab tab;
	private View parent;
	private String windowTitle;
	
	public TabView(View p, Tab t) {
		super();
		parent = p;
		tab = t;
		windowTitle = "Tab File: " + t.getBandName() + " - " + t.getSongName();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setPreferredSize(new java.awt.Dimension(797, 593));
			{
				tabViewPanel = new JPanel();
				getContentPane().add(tabViewPanel);
				tabViewPanel.setLayout(null);
				tabViewPanel.setPreferredSize(new java.awt.Dimension(800, 600));
				{
					tabScrollPane = new JScrollPane();
					tabViewPanel.add(tabScrollPane);
					tabScrollPane.setBounds(12, 41, 766, 517);
					tabScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					{
						tabTextArea = new JTextArea(tab.getTabText());
						tabScrollPane.setViewportView(tabTextArea);
						tabTextArea.setEditable(false);
						tabTextArea.setMargin(new java.awt.Insets(10, 10, 2, 1));
						tabTextArea.setFont(parent.getPreferredFont());
						tabTextArea.setForeground(parent.getPrefFGColor());
						tabTextArea.setBackground(parent.getPrefBGColor());
					}
				}
				{
					saveButton = new JButton();
					tabViewPanel.add(saveButton);
					saveButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("view/icons/save-icon.png")));
					saveButton.setBounds(17, 12, 24, 22);
					saveButton.setBorderPainted(false);
					saveButton.setActionCommand("saveButton");
					saveButton.setToolTipText("Save Tab");
					saveButton.addActionListener(this);
				}
			}
			pack();
			this.setTitle(windowTitle);
			this.setSize(797, 593);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	
	public void actionPerformed(ActionEvent e)	{
		if( e.getActionCommand() == "saveButton" )	{
			if( parent.saveTab(tab) )
				JOptionPane.showMessageDialog(null, "Tab saved locally!" );
			else
				JOptionPane.showMessageDialog(null, "Tab save FAILED!" );			
		}

		if( e.getActionCommand() == "submitButton")	{
			JOptionPane.showMessageDialog(null, "Whence this has been implementado, wust vill submit blob to db.");
		}
	}
	 	
}
